<?php

namespace app\common\model;

use think\facade\Cache;
use think\Model;

class NobleNewModel extends Model
{
    protected static function init()
    {
        static::afterInsert(function ($user) {
            Cache::store('redis')->rm('noble_list');
        });
        static::afterUpdate(function ($user) {
            Cache::store('redis')->rm('noble_list');
        });
        static::afterDelete(function ($user) {
            Cache::store('redis')->rm('noble_list');
        });
    }

    public static function lists(): array
    {
        return Cache::store('redis')->remember('noble_list', function () {
            return static::select()->toArray();
        });
    }
}